﻿using System;
using System.ComponentModel;
using System.Linq.Expressions;

namespace Emico.Linq.Criterion
{
    public static class CriteriaExtends
    {
        #region Order

        public static void AddOrder<T>(this Criteria<T> criteria, string propertyName, bool ascending)
            where T : class
        {
            criteria.Orders.Add(new OrderBy<T>(propertyName, ascending));
        }

        public static void AddOrder<T>(this Criteria<T> criteria, string propertyName, ListSortDirection sortDirection)
            where T : class
        {
            criteria.Orders.Add(new OrderBy<T>(propertyName, sortDirection));
        }

        public static void AddOrder<T>(this Criteria<T> criteria, Expression<Func<T, object>> selector, bool ascending)
            where T : class
        {
            criteria.Orders.Add(new OrderBy<T>(selector, ascending));
        }

        public static void AddOrder<T>(this Criteria<T> criteria, Expression<Func<T, object>> selector, ListSortDirection sortDirection)
            where T : class
        {
            criteria.Orders.Add(new OrderBy<T>(selector, sortDirection));
        }

        #endregion
    }
}
